/*************************************************************************
 * 使用示例：
 *
 * int main(int argc, char *argv[])
 * {
 *     ns::config_t config;
 * 
 *     // 默认设置
 *     {
 *         config.settings = "";
 *         config.count = 0;
 *     }
 * 
 *     // 可解析的参数列表
 *     auto cli =
 *     (
 *         clipp::option( "-i", "--init" ) & clipp::value( "init settings", config.settings ),
 *         clipp::option( "-c", "--count" ) & clipp::value( "count", config.count )
 *     );
 * 
 *     // 如果命令行解析正常则启动应用，否则打印使用帮助
 *     if( clipp::parse( argc, argv, cli ) )
 *     {
 *         return run();
 *     } else {
 *         clipp::man_out( cli, argv[0] );
 * 
 *         return -0xffffff;
 *     }
 * }
 * 
 ************************************************************************/
#ifndef __clipp_kenny_if45jeiji8e3__
#define __clipp_kenny_if45jeiji8e3__

#include "../import/clipp.hpp"
#include <sstream>

namespace clipp
{
      /*************************************************************************
        * @brief   generates man page based on command line parameters
        */
      inline const std::string _man_out(const clipp::group &cli, clipp::doc_string progname = "",
          const clipp::doc_formatting &fmt = clipp::doc_formatting{})
      {
          auto man = clipp::make_man_page( cli, progname, fmt );

          bool first = true;
          const auto secSpc = clipp::doc_string(man.section_row_spacing() + 1, '\n');
          std::ostringstream oss;

          for (const auto &section : man)
          {
              if (!section.content().empty())
              {
                  if (first)
                      first = false;
                  else
                      oss << secSpc;

                  if (!section.title().empty())
                      oss << section.title() << '\n';

                  oss << section.content();
              }
          }

          oss << '\n';

          return oss.str();
      }

      /*************************************************************************
        * @brief   generates man page based on command line parameters
        */
      inline int man_out(const clipp::group &cli, clipp::doc_string progname = "",
          const clipp::doc_formatting &fmt = clipp::doc_formatting{})
      {
          return ::puts( _man_out( cli, progname, fmt ).c_str() );
      }
}

namespace hude
{
    namespace utils
    {
        namespace clipp = ::clipp;
    }
}

#endif  // __clipp_kenny_if45jeiji8e3__
